

import { createRouter, createWebHistory } from "vue-router"
import passport from '@/page/layout/passport/passport.vue'
const login = () => import('@/page/view/passport/login.vue')
import error404 from '@/page/view/exception/404.vue'
const notfound = () => import('@/page/view/exception/notfound.vue')
const basicComponent = () => import('@/page/layout/default/basic.component.vue')
const dashboard = () => import('@/page/view/dashboard/dashboard.vue')
const analysis = () => import('@/page/view/dashboard/analysis.vue')
const basicForm = ()=> import('@/page/view/form/basic-form.vue')
const stepForm = ()=> import('@/page/view/form/step-form.vue')
const richTextEditing = () =>import('@/page/view/form/richTextEditing.vue')
const advancedForm = () => import('@/page/view/form/advanced-form.vue')
const tableList = () =>import('@/page/view/preview/table-list.vue')
const basicDetails = () =>import('@/page/view/details/basic-detail.vue')
const advancedDetail = () =>import('@/page/view/details/advanced-detail.vue')
const videoVue = () =>import('@/page/view/form/video.vue')

import { ACLGuard,SimpleGuard } from "@/package/acl/acl.guard"


const routes = [
  {
    path: "/:pathMatch(.*)*",
    name: "notfound",
    component: notfound,
    meta: { title: 'notfound' }
  },
  {
    path: "/exception/404",
    name: "error404",
    component: error404,
    meta: { title: '404' }
  },
  {
    path: "",
    name: "basicComponent",
    component: basicComponent,
    meta: { title: '仪表盘' },
    beforeEnter: [SimpleGuard],
    children: [
      { path: 'v1', name: "v1", component: dashboard,meta: { title:'默认页' } },
      { path: 'analysis', name: "analysis", component: analysis,meta: { title:'分析页' }},
      { path: '/preview/table-list', name: "table-list", component: tableList,meta: { title:'查询表格' }},
      { path: 'form/rich-text-editing', name: "richTextEditing", component: richTextEditing,meta: { title:'富文本编辑' }},
      { path: '/form/basic-form', name: "basic-form", component: basicForm,meta: { title:'基础表单' }},
      { path: '/form/step-form', name: "step-form", component: stepForm,meta: { title:'分步表单' }},
      { path: '/form/video', name: "videoVue", component: videoVue,meta: { title:'视频' }},
      { path: '/form/advanced-form', name: "advanced-form", component: advancedForm,meta: { title:'高级表单' }},
      { path: '/details/basic-details', name: "basic-details", component: basicDetails,meta: { title:'基础详情页' }},
      { path: '/details/advanced-detail', name: "advanced-detail", component: advancedDetail,meta: { title:'高级详情页' }}
    ]
  },
  {
    path: '/passport', name: "passport", component: passport,
    children: [
      { path: 'login', name: "login", component: login }
    ]
  },
]



const router = createRouter({
  //内部提供了 history 模式的实现。为了简单起见，我们在这里使用 hash 模式。
  history: createWebHistory(),
  routes, // `routes: routes` 的缩写
})


router.beforeEach((to, from, next) => {
  if(to.meta.title){
    document.title = to.meta.title as string
  }
 
  if(to.path=='/'){
    next({path:'/v1'}) 
  }else{
    console.log(to)
    next() 
  }
 
})

router.afterEach((to, from) => {
  
})


export { router, routes }